package model;

import java.util.ArrayList;

import org.bushe.swing.event.EventBus;

import constants.Events;

public class Battle {

	private ArrayList<Question> questions;

	// Perhaps let 'Settings' take care of this
	private int difficulty;

	public Battle(){
		setDifficulty(0);
		questions = new ArrayList<Question>();
		intializeArray(difficulty);
	} //construcor

	/**
	 * Sets the diffuclty at the questions
	 * @param diff How difficulty the questions should be; sets between 0-2
	 */
	public void setDifficulty(int diff){
		this.difficulty = diff;
	} //setDifficulty

	/**
	 * Get the current difficulty
	 * @return 
	 */
	public int getDifficulty(){
		return difficulty;
	} //getDifficulty

	/**
	 * Picks a question at random 
	 * @return Question Object
	 */
	public Question randQuestion() {
		int rand = (int)(Math.floor(Math.random()*(questions.size())));
		return questions.get(rand);
	} //getQuestion

	/**
	 * Set newQuestion into the set of questions 
	 * @param str The new question
	 * @param answer The answer to the question
	 */
	public void setNewQuestion(String str, double answer) {
		Question q = new Question(str, answer);
		questions.add(q);
	}
	
	Question activeQ;
	public Question getQuestion() {
		return activeQ;
	} //getQuestion

	//-------------------------------------//
	// Perhaps set this code into the view // 
	//-------------------------------------//

	/**
	 * Asks the Player a question and tells if it's correct.  
	 * @return True if the players answer is correct 
	 */
	public void askPlayer(){
		
		activeQ = randQuestion();
		String str = activeQ.getQuestion();
		EventBus.publish(Events.BATTLE.toString(), str);
	} //askPlayer


	//------------------------------------//



	/*
	 * Dummy method to intialize the array with some 
	 */
	private void intializeArray(int diff){
		if(diff == 0){
			setNewQuestion("1+2 = ? ", 3);
			setNewQuestion("6+9 = ? ", 15);
			setNewQuestion("7*2 = ? ", 14);
		}
		else if(diff == 1){
			setNewQuestion("7*2 = ? ", 14);
		}
		else if(diff == 2){
			setNewQuestion("cos(2/5) + sin (2/5) = ?", 1.3104793363115357);
			setNewQuestion("convert 142 to base 2 = ?", 10001110);	
		}
	}
}
